# main_window.py - 主窗口架构
from PyQt6.QtWidgets import QMainWindow, QStackedWidget, QWidget, QHBoxLayout
from PyQt6.QtCore import Qt, QSize

from core.navigation import NavigationBar
from views.analysis_view.ND08.controller import DataAnalysisController
from views.analysis_view.ND08.view import DataAnalysisView


class MainWindow(QMainWindow):
	def __init__(self):
		super().__init__()
		
		# 主布局
		self.main_widget = QWidget()
		self.main_layout = QHBoxLayout(self.main_widget)
		
		# 左侧导航栏
		self.sidebar = NavigationBar()
		self.main_layout.addWidget(self.sidebar, stretch=1)
		
		# 右侧内容区
		self.content_area = QStackedWidget()
		self.main_layout.addWidget(self.content_area, stretch=4)
		
		# 创建视图和控制器
		self.analysis_view = DataAnalysisView()
		self.analysis_controller = DataAnalysisController(self.analysis_view)
		
		# 添加到内容区域
		self.content_area.addWidget(self.analysis_view)
		self.sidebar.module_changed.connect(self.switch_module)
		# 初始化界面
		self.setCentralWidget(self.main_widget)
		self.init_ui()
	
	def init_ui(self):
		# 初始化导航栏模块
		self.sidebar.add_module("数据分析", icon="📊")
		self.sidebar.add_module("历史图表", icon="📈")
		
		# 初始化对应页面
		# self.pages = [
		# 	DataAnalysisPage(),
		# 	ChartListPage()
		# ]
		# for page in self.pages:
		# 	self.content_area.addWidget(page)
		# 初始化内容页面
		# self.data_analysis_page = DataAnalysisPage()
		# self.chart_list_page = ChartListPage()
		# self.content_area.addWidget(self.data_analysis_page)
		# self.content_area.addWidget(self.chart_list_page)
	
	def switch_module(self, index):
		"""切换内容页面"""
		if 0 <= index < self.content_area.count():
			self.content_area.setCurrentIndex(index)
			# 更新导航按钮状态
			for i, btn in enumerate(self.sidebar.buttons):
				btn.setChecked(i == index)